package com.example.jh352160.surfingtv.category.customView;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.jh352160.surfingtv.R;

import java.util.List;
import java.util.Map;

/**
 * Created by jh352160 on 2016/7/25
 */

public class CategoryList extends TableLayout {

    CategoryItem categoryItem1, categoryItem2, categoryItem3, categoryItem4;
    List<Map<String, Object>> datas;
    Context context;

    public CategoryList(Context context, List<Map<String, Object>> datas) {
        super(context);
        this.datas = datas;
        this.context = context;
        init();
    }

    public CategoryList(Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.category_list, this);
        categoryItem1 = (CategoryItem) findViewById(R.id.categoryItem1);
        categoryItem2 = (CategoryItem) findViewById(R.id.categoryItem2);
        categoryItem3 = (CategoryItem) findViewById(R.id.categoryItem3);
        categoryItem4 = (CategoryItem) findViewById(R.id.categoryItem4);
        CategoryItem[] items = {categoryItem1, categoryItem2, categoryItem3, categoryItem4};
        for (int i = 0; i < datas.size(); i++) {
            CategoryItem item = items[i];
            ImageView imageView = (ImageView) item.findViewById(R.id.categoryImage);
            TextView categoryName = (TextView) item.findViewById(R.id.categoryName);
            TextView subscribeNumber = (TextView) item.findViewById(R.id.subscribeNumber);
            item.changeStat((boolean) datas.get(i).get("isSubscribed"));
            item.setCategoryId((int) datas.get(i).get("categoryId"));
            //imageView.setImageResource((Integer) datas.get(i).get("imageId"));
            Glide.with(context).load(datas.get(i).get("imageId")).into(imageView);
            categoryName.setText((String) datas.get(i).get("title"));
            subscribeNumber.setText((String) datas.get(i).get("quantity"));
            item.setVisibility(VISIBLE);
        }
    }
}
